if ( age>=21 && credit>=10000 )
The customer must get "true" for both the age test and the credit test. If both tests are passed, the && combines the two true's into true.
A 24 year old customer with $0 credit could not rent a car. The logical expression would look like this:
age >= 21 && credit >= 10000 --------- --------------- true false ---------------- false
true AND false is false.
A "welter weight" boxer must weight between 136 and 147 pounds. A boxer's weight is tested before each fight to be sure that he is within his weight category. Here is a program that checks if a welter weight boxer's weight is within range:
// Ringside Weigh-in
//
// Boxer must weigh between 136 and 147 pounds
//
import java.io.*;
class Ringside
{
public static void main (String[] args) throws IOException
{
BufferedReader stdin =
new BufferedReader ( new InputStreamReader( System.in ) );
String inData;
int weight;
// get the weight
System.out.println("How heavy is the boxer?");
inData = stdin.readLine();
weight = Integer.parseInt( inData );
// check that the weight is within range
if ( _______________________ )
System.out.println("In range!" );
else
System.out.println("Out of range." );
}
}